
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gummworld2.data</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="gummworld2.html"><font color="#ffffff">gummworld2</font></a>.data</strong></big></big> (version $Id: data.py 268 2011-03-11 05:15:37Z stabbingfinger@gmail.com $)</font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:///C:/cygwin/home/bw/devel/python/svn/gummworld2/gamelib/gummworld2/data.py">c:\cygwin\home\bw\devel\python\svn\gummworld2\gamelib\gummworld2\data.py</a></font></td></tr></table>
    <p><tt>data.py&nbsp;-&nbsp;Data&nbsp;resource&nbsp;loader&nbsp;for&nbsp;Gummworld2.<br>
&nbsp;<br>
Module&nbsp;data&nbsp;may&nbsp;be&nbsp;used&nbsp;directly,&nbsp;but&nbsp;use&nbsp;of&nbsp;the&nbsp;module&nbsp;functions&nbsp;is&nbsp;preferred:<br>
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;data_py&nbsp;is&nbsp;the&nbsp;absolute&nbsp;path&nbsp;for&nbsp;this&nbsp;module&nbsp;file's&nbsp;directory.<br>
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;data_dir&nbsp;is&nbsp;the&nbsp;root&nbsp;data&nbsp;directory.<br>
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;subdirs&nbsp;is&nbsp;a&nbsp;dict(name=subdir)&nbsp;for&nbsp;looking&nbsp;up&nbsp;resource&nbsp;sub-directories<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by&nbsp;name.&nbsp;name&nbsp;is&nbsp;simply&nbsp;an&nbsp;abstract&nbsp;type&nbsp;or&nbsp;description.<br>
&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;paths&nbsp;is&nbsp;a&nbsp;"cooked"&nbsp;dict&nbsp;containing&nbsp;lookups&nbsp;for&nbsp;subdirectories&nbsp;of&nbsp;each<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data&nbsp;type.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="os.html">os</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-filepath"><strong>filepath</strong></a>(typ, filename)</dt><dd><tt>Return&nbsp;the&nbsp;path&nbsp;to&nbsp;a&nbsp;file&nbsp;in&nbsp;the&nbsp;data&nbsp;directory.</tt></dd></dl>
 <dl><dt><a name="-load"><strong>load</strong></a>(typ, filename, mode<font color="#909090">='rb'</font>)</dt><dd><tt>Open&nbsp;a&nbsp;file&nbsp;in&nbsp;the&nbsp;data&nbsp;directory&nbsp;and&nbsp;return&nbsp;its&nbsp;file&nbsp;handle.<br>
&nbsp;<br>
The&nbsp;mode&nbsp;argument&nbsp;is&nbsp;passed&nbsp;as&nbsp;the&nbsp;second&nbsp;argument&nbsp;to&nbsp;open().</tt></dd></dl>
 <dl><dt><a name="-load_font"><strong>load_font</strong></a>(filename)</dt><dd><tt>Open&nbsp;a&nbsp;font&nbsp;file&nbsp;from&nbsp;the&nbsp;font&nbsp;dir&nbsp;and&nbsp;return&nbsp;its&nbsp;file&nbsp;handle.</tt></dd></dl>
 <dl><dt><a name="-load_image"><strong>load_image</strong></a>(filename)</dt><dd><tt>Open&nbsp;an&nbsp;image&nbsp;file&nbsp;from&nbsp;the&nbsp;image&nbsp;dir&nbsp;and&nbsp;return&nbsp;its&nbsp;file&nbsp;handle.</tt></dd></dl>
 <dl><dt><a name="-load_map"><strong>load_map</strong></a>(filename)</dt><dd><tt>Open&nbsp;a&nbsp;map&nbsp;file&nbsp;from&nbsp;the&nbsp;map&nbsp;dir&nbsp;and&nbsp;return&nbsp;its&nbsp;file&nbsp;handle.</tt></dd></dl>
 <dl><dt><a name="-load_sound"><strong>load_sound</strong></a>(filename)</dt><dd><tt>Open&nbsp;a&nbsp;sound&nbsp;file&nbsp;from&nbsp;the&nbsp;sound&nbsp;dir&nbsp;and&nbsp;return&nbsp;its&nbsp;file&nbsp;handle.</tt></dd></dl>
 <dl><dt><a name="-load_text"><strong>load_text</strong></a>(filename)</dt><dd><tt>Open&nbsp;a&nbsp;text&nbsp;file&nbsp;from&nbsp;the&nbsp;text&nbsp;dir&nbsp;and&nbsp;return&nbsp;its&nbsp;file&nbsp;handle.</tt></dd></dl>
 <dl><dt><a name="-relpath"><strong>relpath</strong></a>(filename)</dt><dd><tt>Return&nbsp;the&nbsp;file&nbsp;path&nbsp;relative&nbsp;to&nbsp;data_dir.<br>
&nbsp;<br>
For&nbsp;example:<br>
&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;data.data_dir&nbsp;is&nbsp;"/games/pong/data"<br>
&nbsp;&nbsp;&nbsp;&nbsp;filename&nbsp;=&nbsp;"/games/pong/data/image/my.png"<br>
&nbsp;&nbsp;&nbsp;&nbsp;relname&nbsp;=&nbsp;data.<a href="#-relpath">relpath</a>(filename)<br>
&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;relname&nbsp;is&nbsp;"image/my.png"</tt></dd></dl>
 <dl><dt><a name="-set_data_dir"><strong>set_data_dir</strong></a>(base)</dt><dd><tt>Set&nbsp;the&nbsp;base&nbsp;data&nbsp;directory&nbsp;for&nbsp;game&nbsp;resources.<br>
&nbsp;<br>
base&nbsp;may&nbsp;be&nbsp;a&nbsp;relative&nbsp;or&nbsp;absolute&nbsp;path.&nbsp;It&nbsp;will&nbsp;be&nbsp;converted&nbsp;to&nbsp;an&nbsp;absolute<br>
path&nbsp;and&nbsp;then&nbsp;normalized.<br>
&nbsp;<br>
Calling&nbsp;this&nbsp;function&nbsp;changes&nbsp;the&nbsp;base&nbsp;data&nbsp;directory.&nbsp;The&nbsp;full&nbsp;path&nbsp;to&nbsp;a<br>
data&nbsp;resource&nbsp;is&nbsp;constructed&nbsp;by&nbsp;joining&nbsp;data_dir&nbsp;and&nbsp;a&nbsp;subdir.<br>
&nbsp;<br>
The&nbsp;default&nbsp;data&nbsp;directory&nbsp;is&nbsp;'../../data',&nbsp;relative&nbsp;to&nbsp;the&nbsp;path&nbsp;of&nbsp;this<br>
module&nbsp;file.<br>
&nbsp;<br>
NOTE:&nbsp;Call&nbsp;this&nbsp;early,&nbsp;before&nbsp;attempting&nbsp;to&nbsp;construct&nbsp;any&nbsp;library&nbsp;objects&nbsp;or<br>
load&nbsp;resources.<br>
&nbsp;<br>
Any&nbsp;previously&nbsp;loaded&nbsp;resources&nbsp;are&nbsp;unaffected.&nbsp;However,&nbsp;there&nbsp;may&nbsp;be<br>
side-effects,&nbsp;for&nbsp;example&nbsp;memory&nbsp;leaks&nbsp;if&nbsp;a&nbsp;user-defined&nbsp;caching&nbsp;mechanism<br>
uses&nbsp;data&nbsp;paths&nbsp;to&nbsp;fetch&nbsp;resources&nbsp;from&nbsp;cache.</tt></dd></dl>
 <dl><dt><a name="-set_subdir"><strong>set_subdir</strong></a>(name, subdir)</dt><dd><tt>Set&nbsp;or&nbsp;add&nbsp;a&nbsp;new&nbsp;sub-directory&nbsp;for&nbsp;game&nbsp;resources.<br>
&nbsp;<br>
name&nbsp;is&nbsp;the&nbsp;unique&nbsp;key&nbsp;used&nbsp;to&nbsp;look&nbsp;up&nbsp;the&nbsp;resource&nbsp;location.&nbsp;subdir&nbsp;is&nbsp;the<br>
path&nbsp;component(s)&nbsp;to&nbsp;append&nbsp;to&nbsp;the&nbsp;data_path&nbsp;base&nbsp;directory.<br>
&nbsp;<br>
subdir&nbsp;is&nbsp;assumed&nbsp;to&nbsp;be&nbsp;a&nbsp;relative&nbsp;path&nbsp;and&nbsp;is&nbsp;taken&nbsp;at&nbsp;face&nbsp;value.&nbsp;No<br>
sanity&nbsp;or&nbsp;access&nbsp;checks&nbsp;are&nbsp;performed.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__author__</strong> = 'Gummbum, (c) 2011'<br>
<strong>__version__</strong> = '$Id: data.py 268 2011-03-11 05:15:37Z stabbingfinger@gmail.com $'<br>
<strong>data_dir</strong> = r'C:\cygwin\home\bw\devel\python\svn\gummworld2\data'<br>
<strong>data_py</strong> = r'C:\cygwin\home\bw\devel\python\svn\gummworld2\gamelib\gummworld2'<br>
<strong>paths</strong> = {'font': r'C:\cygwin\home\bw\devel\python\svn\gummworld2\data\font', 'image': r'C:\cygwin\home\bw\devel\python\svn\gummworld2\data\image', 'map': r'C:\cygwin\home\bw\devel\python\svn\gummworld2\data\map', 'sound': r'C:\cygwin\home\bw\devel\python\svn\gummworld2\data\sound', 'text': r'C:\cygwin\home\bw\devel\python\svn\gummworld2\data\text', 'theme': r'C:\cygwin\home\bw\devel\python\svn\gummworld2\data\themes'}<br>
<strong>subdirs</strong> = {'font': 'font', 'image': 'image', 'map': 'map', 'sound': 'sound', 'text': 'text', 'theme': 'themes'}</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Gummbum,&nbsp;(c)&nbsp;2011</td></tr></table>
</body></html>